import { delToken, setToken } from '@/utils/auth'
import request from '@/utils/request'
/**
 *
 * @param {*} formData {mobile,code}
 */
export function loginAction(formData) {
  return async dispatch => {
    // 1. 获取token
    const { data } = await request.post('/authorizations', formData)
    console.log('2登录:', data.token)
    // 2. 存储token到redux，同时本地存储一份
    dispatch({
      type: 'token/login',
      token: data.token
    })
    setToken(data.token)
    // localStorage.setItem('geek-token', data.token)
  }
}
export function logoutAction() {
  return dispatch => {
    //  删除token和用户信息
    dispatch({
      type: 'clear/login'
    })
    delToken()
    dispatch({
      type: 'clear/user'
    })
  }
}
